package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.entity.AppCommentT;
import com.panshi.service.impl.AppCommentTServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资讯、问题评论表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-04
 */
@RestController
public class AppCommentTController {

    @Autowired
    private AppCommentTServiceImpl appCommentTService;

    @ApiOperation("查询全部评论")
    @GetMapping("/app-comment-t/all")
    public List<AppCommentT> all(){
        return appCommentTService.list(null);
    }

    @ApiOperation("添加评论")
    @PostMapping("/app-comment-t/commAdd")
    public Boolean commAdd(@RequestBody AppCommentT appCommentT){
        return appCommentTService.save(appCommentT);
    }

    @ApiOperation("按咨询表ID 查询咨询评论")
    @GetMapping("/app-comment-t/commZxId/{zxId}/{page}/{limit}")
    public List<AppCommentT> commZxId(@PathVariable int zxId,@PathVariable int page,@PathVariable int limit){
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<AppCommentT> pageParam = new Page<>(page, limit);
        QueryWrapper wrapper = new QueryWrapper<AppCommentT>();
        wrapper.eq("comment_type","zx");
        wrapper.eq("comment_id",zxId);
        wrapper.ne("is_remove","1");    //不查询被删除的评论
        appCommentTService.page(pageParam,wrapper);
        List<AppCommentT> commentTS = pageParam.getRecords();

        return commentTS;
    }

    @ApiOperation("查询评论的评论")
    @GetMapping("/app-comment-t/getCommById/{commId}")
    public List<AppCommentT> getCommById(@PathVariable int commId){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("cover_user_id",commId);
        wrapper.eq("is_remove","0");
        return appCommentTService.list(wrapper);
    }


    @ApiOperation("按咨询表ID 查询咨询评论")
    @GetMapping("/app-comment-t/commQaId/{qaId}/{page}/{limit}")
    public List<AppCommentT> commQaId(@PathVariable int qaId,@PathVariable int page,@PathVariable int limit){
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<AppCommentT> pageParam = new Page<>(page, limit);
        QueryWrapper wrapper = new QueryWrapper<AppCommentT>();
        wrapper.eq("comment_type","m");
        wrapper.eq("comment_id",qaId);
        wrapper.ne("is_remove","1");//不查询被删除的评论
        appCommentTService.page(pageParam,wrapper);
        List<AppCommentT> commentTS = pageParam.getRecords();

        return commentTS;
    }



}

